package com.lixinyue.array;
//二分法
public class demo06 {
    public static void main(String[] args) {
   int[]arr=new int[]{12,34,45,67,78,89,90,111,234,567,899};
   int dest=111;
   int left=0;
   int right= arr.length-1;

    boolean flag=true;
   while(left<=right)
   {
       int mid=(left+right)/2;
       if(arr[mid]<dest)
       {
           left=mid+1;

       }
       if(arr[mid]>dest)
       {
           right=mid-1;
       }
       if(arr[mid]==dest)
       {
           System.out.println("找到了，位置为"+mid);
           flag=false;
           break;
       }
   }
   if(flag==true)
   {
       System.out.println("很遗憾，没有找到");
   }
    }
}
